

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>数据操作 - 数据表格</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
</head>
<body>

  <div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
      <a lay-href="">主页</a>
      <a><cite>组件</cite></a>
      <a><cite>数据表格</cite></a>
      <a><cite>数据操作</cite></a>
    </div>
  </div>
  
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">通知和公告</div>
          <div class="layui-card-body">
            <div class="test-table-reload-btn" style="margin-bottom: 10px;">
                <div class="layui-btn-group demoTable" style="margin-bottom: 10px;">
                  <button class="layui-btn" data-type="getCheckData">全部公告</button>
                  <button class="layui-btn" data-type="getCheckLength">未读公告（5）</button>
                  <button class="layui-btn" data-type="isAll">已读公告</button>

                  <!-- <button class="layui-btn" data-type="publish" id="LAY_layer_iframe_demo">发布</button> -->
                </div>

                <!-- <form class="layui-form layui-form-pane" action="">
                    搜索ID：
                    <div class="layui-inline">
                      <input class="layui-input" name="id" id="test-table-demoReload" autocomplete="off">
                    </div>

                    <div class="layui-inline">
                        <select name="quiz">
                          <option value="">请选择问题</option>
                          <option value="你工作的第一个城市">你工作的第一个城市</option>
                          <option value="你的工号">你的工号</option>
                          <option value="你最喜欢的老师">你最喜欢的老师</option>
                        </select>
                    </div>

                    <button class="layui-btn" data-type="reload">搜索</button>
                </form> -->
            </div>
            
            <table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table>
            
            <script type="text/html" id="test-table-operate-barDemo">
              <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            </script>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="../../layuiadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: '../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table'], function(){
    var $ = layui.$
    ,admin = layui.admin
    ,table = layui.table
    ,element = layui.element
    ,layer = layui.layer;

    element.render();
    
    
    
  
    table.render({
      elem: '#test-table-operate'
      ,url: layui.setter.base + 'json/table/page3.js'
      ,width: admin.screen() > 1 ? '' : ''
      ,height: ''
      ,cols: [[
        {type: 'numbers', fixed: 'left'}
        // ,{field:'id', width:80, title: 'ID', fixed: 'left'}
        ,{field:'title', title: '标题'}
        ,{field:'score', width:180, title: '时间', fixed: 'right'}
      ]]
      ,page: true
    });
    
    //监听表格复选框选择
    table.on('checkbox(test-table-operate)', function(obj){
      console.log(obj)
    });
    
    
    var $ = layui.$, active = {
      getCheckData: function(){ //获取选中数据
        var checkStatus = table.checkStatus('test-table-operate')
        ,data = checkStatus.data;
        layer.alert(JSON.stringify(data));
      }
      ,getCheckLength: function(){ //获取选中数目
        var checkStatus = table.checkStatus('test-table-operate')
        ,data = checkStatus.data;
        layer.msg('选中了：'+ data.length + ' 个');
      }
      ,isAll: function(){ //验证是否全选
        var checkStatus = table.checkStatus('test-table-operate');
        layer.msg(checkStatus.isAll ? '全选': '未全选')
      }

      
      ,publish: function(){
        layer.open({
          type: 2,
          area: ['700px', '450px'],
          fixed: false,
          maxmin: true,
          content: '../iframe/layer/iframe_page3.html'
        });
      }
    };

    $('#LAY_layer_iframe_demo').on('click', function(){
      var type = $(this).data('type');
      active[type] && active[type].call(this);
    });
    
    $('.test-table-operate-btn .layui-btn').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  
  });
  </script>
</body>
</html>